search_tweets()get_trends()stream_tweets()get_friends() get_followers()get_timelines()get_favorites()%>%%>%%>%%>%%>%%>%rtweet function like search_tweets()retryonratelimit = TRUEpost_tweet(
status = "Hey @Satrdays_DC, did you know you can
post a Tweet directly from #rstats?",
media = "images/no_way.gif"
)search_tweets()search_tweets("#rladies", n = 5000, include_rts = FALSE) %>%
ts_plot("days", trim = 1L) +
geom_point() + theme_minimal() +
theme(plot.title = element_text(face = "bold")) +
labs(x = NULL, y = NULL,
title = "Frequency of #rladies Twitter Hashtag Usage",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson")get_trends()get_trends("washington") %>% # trends_available() to see locales
top_n(3, tweet_volume) %>% # Pull top 3 trends by volume
ggplot() +
geom_bar(mapping = aes(x = reorder(trend, -tweet_volume), y = tweet_volume),
stat = "identity") +
scale_y_continuous(labels = comma) +
theme(axis.title.x = element_blank()) +
theme(axis.title.y = element_blank()) +
labs(title = "Washington DC Twitter Trends",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson")stream_tweets()rstats <- stream_tweets("rstats", timeout = 60 * 60) # = mins x sesc = 60 min
rstats %>%
ts_plot("mins", trim = 1L) +
geom_point() + theme_minimal() +
theme(plot.title = element_text(face = "bold")) +
labs(x = NULL, y = NULL,
title = "Frequency of #rstats Twitter Mentions",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson")get_timelines()get_timelines(c("dataandme", "thomas_mock", "CMastication"), n = 5000) %>%
filter(created_at > "2020-01-01") %>% group_by(screen_name) %>%
ts_plot("days", trim = 1L) +
geom_point() + theme_minimal() +
theme(legend.position = "bottom",
plot.title = element_text(face = "bold")) +
labs(x = NULL, y = NULL,
title = "Frequency of Tweets by Cool #rstats Twitter Folks",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson")get_favorites()hadley_favs <- get_favorites('hadleywickham', n = 1000)
hadley_fav_count <- hadley_favs %>% group_by(screen_name) %>%
summarize(n = n()) %>% arrange(desc(n))
hadley_fav_count %>% top_n(5, n) %>%
ggplot() +
geom_col(mapping = aes(x = fct_reorder(screen_name, -n), y = n)) +
scale_y_continuous(labels = comma) +
theme(axis.title.x = element_blank()) +
theme(axis.title.y = element_blank()) +
labs(title = "Users Hadley Most Recently Favorited by Count",
caption = "\nSource: Data collected via rtweet - graphic by @mjhendrickson")# Credit to @PaulCampbell91 for the borrowed code
rstaters <- c("mjhendrickson", "CMastication", "thomas_mock",
"kearneymw", "LittleMissData", "AnnaHenschel")
followers_upset <- map_df(rstaters, ~ get_followers(
.x, n=100000, retryonratelimit = TRUE) %>% mutate(account = .x))
aRdent_followers <- unique(followers_upset$user_id)
binaries <- rstaters %>%
map_dfc(~ ifelse(aRdent_followers %in% filter(
followers_upset, account == .x)$user_id, 1, 0) %>% as.data.frame)
names(binaries) <- rstaters
upset(binaries,
nsets = 6,
main.bar.color = "SteelBlue",
sets.bar.color = "DarkCyan",
sets.x.label = "Follower Count",
text.scale = c(rep(1.4, 5), 1),
order.by = "freq")For a full list of what’s included in the data pull, go to the Tweet Data Dictionary
A few of interest:
created_at = UTC time of Tweet
df$created_at - 18000 # 5 hours in seconds for Eastern Timetext = content of the Tweetsource = utility used to post the Tweetis_retweet = TRUE/FALSE if this was a re-tweetfavorite_count = number of times the Tweet was favoritedretweet_count = number of times the Tweet was re-tweetedhashtags = string of all hashtags usedurls_url = string of all urlsmentions_screen_name = string of screen_names mentionedprint(colnames(search_tweets("#rladies", n = 1, include_rts = FALSE)))
#> [1] "user_id" "status_id"
#> [3] "created_at" "screen_name"
#> [5] "text" "source"
#> [7] "display_text_width" "reply_to_status_id"
#> [9] "reply_to_user_id" "reply_to_screen_name"
#> [11] "is_quote" "is_retweet"
#> [13] "favorite_count" "retweet_count"
#> [15] "quote_count" "reply_count"
#> [17] "hashtags" "symbols"
#> [19] "urls_url" "urls_t.co"
#> [21] "urls_expanded_url" "media_url"
#> [23] "media_t.co" "media_expanded_url"
#> [25] "media_type" "ext_media_url"
#> [27] "ext_media_t.co" "ext_media_expanded_url"
#> [29] "ext_media_type" "mentions_user_id"
#> [31] "mentions_screen_name" "lang"
#> [33] "quoted_status_id" "quoted_text"
#> [35] "quoted_created_at" "quoted_source"
#> [37] "quoted_favorite_count" "quoted_retweet_count"
#> [39] "quoted_user_id" "quoted_screen_name"
#> [41] "quoted_name" "quoted_followers_count"
#> [43] "quoted_friends_count" "quoted_statuses_count"
#> [45] "quoted_location" "quoted_description"
#> [47] "quoted_verified" "retweet_status_id"
#> [49] "retweet_text" "retweet_created_at"
#> [51] "retweet_source" "retweet_favorite_count"
#> [53] "retweet_retweet_count" "retweet_user_id"
#> [55] "retweet_screen_name" "retweet_name"
#> [57] "retweet_followers_count" "retweet_friends_count"
#> [59] "retweet_statuses_count" "retweet_location"
#> [61] "retweet_description" "retweet_verified"
#> [63] "place_url" "place_name"
#> [65] "place_full_name" "place_type"
#> [67] "country" "country_code"
#> [69] "geo_coords" "coords_coords"
#> [71] "bbox_coords" "status_url"
#> [73] "name" "location"
#> [75] "description" "url"
#> [77] "protected" "followers_count"
#> [79] "friends_count" "listed_count"
#> [81] "statuses_count" "favourites_count"
#> [83] "account_created_at" "verified"
#> [85] "profile_url" "profile_expanded_url"
#> [87] "account_lang" "profile_banner_url"
#> [89] "profile_background_url" "profile_image_url"This talk is freely distributed under the MIT License.
(So is rtweet!)
Social Network Analysis